#include <stdio.h>
int Is_leapyear(int year){
	if((year % 4 == 0&&year % 100 != 0)||(year % 400 == 0))
		return 1;
	else
		return 0;
}
int main(){
    int mon[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
    int year = 0;
    int month = 0;
    while(scanf("%d %d",&year,&month) != EOF){
    	if(Is_leapyear(year) == 1 && month == 2){
			printf("%d\n",mon[1] + 1);
		}
		else{
			printf("%d\n",mon[month - 1]);
		}
	}
    return 0;
}
